<div class="layui-fluid" id="VIEW-list-table" lay-title="盘点列表" lig-title="inv-title">
    <div class="layui-row layui-col-space10">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header" lig-lang="label-searchTitle">筛选数据</div>
                <div class="layui-card-body">
                    <form class="layui-form" lay-filter="lig-inventory-searchform">
                        <div class="layui-row">
                            <div class="layui-inline">
                                <label class="layui-form-label" lig-lang="inv-pdbCode">盘点编号</label>
                                <div class="layui-inline">
                                    <input type="text" class="layui-input" name="pdbCode" />
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" lig-lang="inv-spwz">商品位置</label>
                                <div class="layui-inline">
                                    <select name="spwz">
                                        <option value=""></option>
                                    </select>
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label" style="width:85px;" lig-lang="inv-pdqzsj">盘点起止时间</label>
                                <div class="layui-inline">
                                    <input type="text" name="pdsjQs" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-inline">--</div>
                                <div class="layui-inline">
                                    <input type="text" name="pdsjJs" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-row layui-col-space10">
                                    <div class="layui-col-xs6">
                                        <div class="layui-btn layui-btn-sm layui-btn-fluid" lay-filter="lig-inventory-search" lig-lang="btn-search">查询</div>
                                    </div>
                                    <div class="layui-col-xs6">
                                        <button type="reset" class="layui-btn layui-btn-sm layui-btn-primary" lig-lang="btn-reset">重置</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="layui-card" id="dy">
                <div class="layui-card-body nepadmin-table-full">
                    <div class="layui-row">
                        <table lay-filter="lig-inventory-table"></table>
                    </div>
                    <div class="layui-row">
                        <div class="layui-tab layui-tab-card">
                            <ul class="layui-tab-title">
                                <li class="layui-this" lig-lang="inv-summaryInfo">盘点汇总</li>
                                <li lig-lang="inv-detailInfo">盘点明细</li>
                            </ul>
                            <div class="layui-tab-content">
                                <div class="layui-tab-item layui-show">
                                    <div class="layui-btn-container nepadmin-pad-t10 nepadmin-pad-l10">
                                        <div class="layui-btn layui-btn-sm" lay-filter="lig-inventory-summary-print" lig-lang="btn-print">打印</div>
                                    </div>
                                    <table lay-filter="lig-inventory-summary-table"></table>
                                </div>
                                <div class="layui-tab-item">
                                    <table lay-filter="lig-inventory-goods-table"></table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div id="summary-print" style="display:none;">
        <table style="width:100%;" border="1" align="center" cellspacing="1">
            <thead>
            <tr>
                <th width="70%" align="center" lig-lang="inv-summarySpmc">名称</th>
                <th width="30%" align="center" lig-lang="inv-sl">数量</th>
            </tr>
            </thead>
            <tbody id="summary-print-data">

            </tbody>
        </table>
    </div>
</div>

<script type="text/html" id="tpl-summary-print-data">
    {{# layui.each(d, function(i, it){ }}
    <tr>
        <td width="70%" align="left">{{ it.spmc }}</td>
        <td width="30%" align="center">{{ it.sl }}</td>
    </tr>
    {{#  }); }}
</script>
<script>
    layui.use(['admin', 'table', 'form', 'dropdown', 'laytpl', 'laydate', 'jquery','lig'], function (admin, table, form, dropdown, laytpl, laydate, $, lig) {

        var _searchForm = '[lay-filter="lig-inventory-searchform"]';
        lig.loadSelectDict('goods_spwz', _searchForm + ' select[name="spwz"]');
        laydate.render({
            elem: _searchForm + ' input[name="pdsjQs"]'
        });
        laydate.render({
            elem: _searchForm + ' input[name="pdsjJs"]'
        });
        $('[lay-filter="lig-inventory-summary-print"]').click(function () {
            printInventory();
        });
        form.render();

        lig.table({
            elem: '[lay-filter="lig-inventory-table"]',
            url: 'pd/inventory/page',
            height: 'full-320',
            cols: [[
                { title: '<span lig-lang="inv-pdbCode">盘点表编号</span>', field: 'pdbCode', minWidth: 120 },
                { title: '<span lig-lang="inv-spwz">商品位置</span>', field: 'spwzmc', minWidth: 120 },
                { title: '<span lig-lang="inv-pdsj">盘点时间</span>', field: 'pdsj', minWidth: 120 },
                { title: '<span lig-lang="inv-czr">操作人</span>', field: 'czr', minWidth: 120 }

            ]]
        },{mode:'dialog',
            entity: 'inventory',
            primaryField: 'inventoryId'
        });

        table.on('row(lig-inventory-table)', function(obj){
            var data = obj.data;
            renderSummaryPrintData(data.pdbCode);
            renderSummary(data.pdbCode);
            renderGoods(data.pdbCode);
        });

        function renderSummary(pdbCode) {
            lig.table({
                elem: '[lay-filter="lig-inventory-summary-table"]',
                url: 'pd/inventory/summary/page?pdbCode=' + pdbCode,
                height: 'full-320',
                cols: [[
                    { title: '<span lig-lang="inv-spbh">商品编号</span>', field: 'spbh', minWidth: 120 },
                    { title: '<span lig-lang="inv-splb">商品类别</span>', field: 'splbmcfj', minWidth: 120 },
                    { title: '<span lig-lang="inv-spmc">商品名称</span>', field: 'spmc', minWidth: 120 },
                    { title: '<span lig-lang="inv-sl">数量</span>', field: 'sl', minWidth: 120 },
                ]]
            });
        }

        function renderGoods(pdbCode) {
            lig.table({
                elem: '[lay-filter="lig-inventory-goods-table"]',
                url: 'pd/inventory/goods/page?pdbCode' + pdbCode,
                height: 'full-320',
                cols: [[
                    { title: '<span lig-lang="inv-spbh">商品编号</span>', field: 'spbh', minWidth: 120 },
                    { title: '<span lig-lang="inv-splb">商品类别</span>', field: 'splbmcfj', minWidth: 120 },
                    { title: '<span lig-lang="inv-txm">珠宝编号</span>', field: 'txm', minWidth: 120 },
                    { title: '<span lig-lang="inv-tid">tid</span>', field: 'tid', minWidth: 120 },
                ]]
            });
        }

        function renderSummaryPrintData(pdbCode) {
            lig.ajaxget({
                url: 'pd/inventory/summary/page?pageSize=2000&pdbCode=' + pdbCode,
                success: function (res) {
                    if (res.data.items.length > 0) {
                        laytpl($('#tpl-summary-print-data').html()).render(res.data.items, function(html){
                            $('#summary-print-data').html(html);
                        });
                    }
                }
            });
        }
        
        function printInventory() {
            $('#summary-print').show();
            Print('#summary-print', {
                onStart: function () {
                },
                onEnd: function () {
                    $('#summary-print').hide();
                }
            });
        }
    });
</script>
